
// ReportView.cpp : implementation of the CReportView class
//

#include "stdafx.h"
#include "Bloodlead.h"

#include "BloodleadDoc.h"
#include "ReportView.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif


// CReportView

IMPLEMENT_DYNCREATE(CReportView, CListView)

BEGIN_MESSAGE_MAP(CReportView, CListView)
	ON_WM_STYLECHANGED()
END_MESSAGE_MAP()

// CReportView construction/destruction

CReportView::CReportView()
{
	// TODO: add construction code here

}

CReportView::~CReportView()
{
}

BOOL CReportView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	if( CListView::PreCreateWindow(cs) )
	{
		cs.style &= ~(LVS_SORTASCENDING | LVS_SORTDESCENDING);

		cs.style |= LVS_REPORT;
		cs.dwExStyle |= LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES | LVS_EX_HEADERDRAGDROP | LVS_EX_TRACKSELECT;
		return TRUE;
	}

	return FALSE;
}

void CReportView::OnInitialUpdate()
{
	CListView::OnInitialUpdate();

	// TODO: You may populate your ListView with items by directly accessing
	//  its list control through a call to GetListCtrl().
	GetListCtrl().InsertColumn( 0, _T("X"), LVCFMT_LEFT, 100 );
	GetListCtrl().InsertColumn( 1, _T("Y"), LVCFMT_LEFT, 100 );
	GetListCtrl().InsertColumn( 2, _T("X*Y"), LVCFMT_LEFT, 100 );
	GetListCtrl().InsertColumn( 3, _T("X*X"), LVCFMT_LEFT, 100 );
	GetListCtrl().InsertColumn( 4, _T("Y*Y"), LVCFMT_LEFT, 100 );

}


// CReportView diagnostics

#ifdef _DEBUG
void CReportView::AssertValid() const
{
	CListView::AssertValid();
}

void CReportView::Dump(CDumpContext& dc) const
{
	CListView::Dump(dc);
}

CBloodleadDoc* CReportView::GetDocument() const // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CBloodleadDoc)));
	return (CBloodleadDoc*)m_pDocument;
}
#endif //_DEBUG


// CReportView message handlers
void CReportView::OnStyleChanged(int nStyleType, LPSTYLESTRUCT lpStyleStruct)
{
	//TODO: add code to react to the user changing the view style of your window	
	CListView::OnStyleChanged(nStyleType,lpStyleStruct);	
}

void CReportView::OnUpdate(CView* /*pSender*/, LPARAM /*lHint*/, CObject* /*pHint*/)
{
	// TODO: Add your specialized code here and/or call the base class
	CListCtrl& list = GetListCtrl();
	CBloodleadDoc* pDoc = GetDocument();
	if( pDoc )
	{
		list.DeleteAllItems();
		for( int i =0; i < pDoc->RecordCount(); ++i )
		{
			CString str;
			str.Format( _T("%5.5f"), pDoc->GetElcValueX(i) );
			int item = list.InsertItem( i, str );
			str.Format( _T("%5.5f"), pDoc->GetElcValueY(i) );
			list.SetItemText( item, 1, str );
			str.Format( _T("%5.5f"), pDoc->GetElcValueXY(i) );
			list.SetItemText( item, 2, str );
			str.Format( _T("%5.5f"), pDoc->GetElcValueXX(i) );
			list.SetItemText( item, 3, str );
			str.Format( _T("%5.5f"), pDoc->GetElcValueYY(i) );
			list.SetItemText( item, 4, str );

		}
	}
}
